/*
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.eclipse.imagen;

import java.beans.PropertyChangeEvent;

/**
 * A class instances of which represent Java Bean-style events emitted by JAI objects. This class definition adds no
 * functionality to that provided by the superclass. The significance of the derivation is that bean events will be
 * easily identifiable as having been generated by JAI classes by virtue of their being instances of this event class.
 * Note that this does not prevent JAI properties from colliding with other Java Bean properties in the Bean property
 * name space.
 *
 * @since JAI 1.1
 */
public class PropertyChangeEventJAI extends PropertyChangeEvent {
    /** The case-retained property name as supplied to the constructor. */
    private String originalPropertyName;

    /**
     * Constructs a <code>PropertyChangeEventJAI</code>. <code>propertyName</code> is forced to lower case; all other
     * parameters are passed unmodified to the superclass constructor. The original property name may be obtained by
     * invoking <code>getOriginalPropertyName()</code>.
     *
     * @exception NullPointerException if <code>propertyName</code> is <code>null</code>.
     * @exception IllegalArgumentException if <code>source</code> is <code>null</code> or if <code>oldValue</code> and
     *     <code>newValue</code> are both <code>null</code>.
     */
    public PropertyChangeEventJAI(Object source, String propertyName, Object oldValue, Object newValue) {
        super(source, propertyName.toLowerCase(), oldValue, newValue);

        if (source == null) {
            throw new IllegalArgumentException(JaiI18N.getString("PropertyChangeEventJAI0"));
        } else if (oldValue == null && newValue == null) {
            throw new IllegalArgumentException(JaiI18N.getString("PropertyChangeEventJAI1"));
        }

        originalPropertyName = propertyName.equals(getPropertyName()) ? getPropertyName() : propertyName;
    }

    /**
     * Returns the value of <code>propertyName</code> originally passed to the class constructor. This name has its case
     * retained.
     */
    public String getOriginalPropertyName() {
        return originalPropertyName;
    }
}
